<?php
/**
 * Created by PhpStorm.
 * User: yunpeng
 * Date: 2019/1/4
 * Time: 13:50
 */

namespace App\Admin\Controllers;

use App\Models\UsersCount;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\DB;
use Zend\Diactoros\Request;
use Encore\Admin\Widgets\Box;
use Encore\Admin\Widgets\Collapse;
use Encore\Admin\Widgets\InfoBox;
use Encore\Admin\Widgets\Tab;

class UsersCountController  extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {
            $content->header('用户统计');
            $content->body($this->grid());
        });
    }





    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(UsersCount::class, function (Grid $grid) {



            $sum = DB::table('users_counts')->sum('sum');
            echo $sum;
            $grid->filter(function($filter){

                // 去掉默认的id过滤器
                $filter->disableIdFilter();

                // 在这里添加字段过滤器
                $filter->between('date_str','日期')->date();

            });

            $grid->date_str('日期');
            $grid->sum('总数');
            $grid->grade0('普通会员');
            $grid->grade1('一级会员');
            $grid->grade2('二级会员');
            $grid->grade3('三级会员');
            $grid->grade4('四级会员');
            $grid->grade5('五级会员');
            $grid->grade6('六级会员');
            $grid->grade7('七级会员');
            $grid->disableCreateButton();
            $grid->disableExport();
            $grid->disableActions();
            //禁用批量删除按钮
            $grid->tools(function ($tools) {
                $tools->batch(function ($batch) {
                    $batch->disableDelete();
                });
            });
        });
    }

}
